package com.china08.yxyapi.repository.db;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.china08.yxyapi.entity.db.lessons.YxyLessonsSynchroLesson;

public interface YxyLessonsSynchroLessonRepository
        extends JpaRepository<YxyLessonsSynchroLesson, String> {

    YxyLessonsSynchroLesson findById(String lessonId);

    Page<YxyLessonsSynchroLesson> findByNameContaining(String name,
            Pageable pageable);

    List<YxyLessonsSynchroLesson> findTop2ByCatalogId(String catalogId);

    List<YxyLessonsSynchroLesson> findTop2ByAuthor(String aaName);

    Page<YxyLessonsSynchroLesson> findByStatusAndIsVisibleAndNameContaining(
            int i, int j, String name, Pageable pageable);

    List<YxyLessonsSynchroLesson> findTop2ByAuthorAndStatusAndIsVisible(
            String aaName, int i, int j);

    List<YxyLessonsSynchroLesson> findTop2ByCatalogIdAndStatusAndIsVisible(
            String catalogId, int i, int j);

    List<YxyLessonsSynchroLesson> findTop2ByAuthorAndStatusAndIsVisibleOrderByVvDesc(
            String aaName, int i, int j);

    List<YxyLessonsSynchroLesson> findTop2ByCatalogIdAndStatusAndIsVisibleOrderByVvDesc(
            String catalogId, int i, int j);

    List<YxyLessonsSynchroLesson> findByStatusAndIsVisibleOrderByCreatedDateDesc(
            int i, int j);

    @Query(value = "SELECT * FROM yxy_lessons.yxy_lessons_synchro_lesson t1  LEFT JOIN yxy_lessons.yxy_lessons_synchro_catalog t2 ON t1.catalog_id = t2.id  WHERE  t1.status = 2 AND t1.is_visible = 1 AND t2.stage_id = '01' ORDER BY  t1.up_date desc LIMIT 3", nativeQuery = true)
    List<YxyLessonsSynchroLesson> findPrimaryLesson();

    @Query(value = "SELECT * FROM yxy_lessons.yxy_lessons_synchro_lesson t1  LEFT JOIN yxy_lessons.yxy_lessons_synchro_catalog t2 ON t1.catalog_id = t2.id  WHERE  t1.status = 2 AND t1.is_visible = 1 AND t2.stage_id ='02' ORDER BY  t1.up_date desc LIMIT 3", nativeQuery = true)
    List<YxyLessonsSynchroLesson> findJuniorLesson();

    @Query(value = "SELECT * FROM yxy_lessons.yxy_lessons_synchro_lesson t1  LEFT JOIN yxy_lessons.yxy_lessons_synchro_catalog t2 ON t1.catalog_id = t2.id  WHERE  t1.status = 2 AND t1.is_visible = 1 AND t2.stage_id ='03' ORDER BY  t1.up_date desc LIMIT 2", nativeQuery = true)
    List<YxyLessonsSynchroLesson> findHighLesson();

    List<YxyLessonsSynchroLesson> findTop2ByCatalogIdInAndStatusAndIsVisibleOrderByVvDesc(
            List<String> catalogIdLst, int i, int j);

}
